package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.entity.Transaction;
import com.sky.vo.GModelInfoVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface GModelMapper {

  Page<GModelInfoVO> modelsPageModelsQuery();


  @Insert("INSERT INTO transactions (model_id, guser_id, start_time, end_time, result_path,count_samples) " +
      "VALUES (#{modelId}, #{guserId}, #{startTime}, #{endTime}, #{resultPath} , #{countSamples})")
  @Options(useGeneratedKeys = true, keyProperty = "tranId")
  void insertRecord(Transaction transaction);

  @Select("select * from transactions where guser_id = #{guserId}")
  Page<Transaction> recordsPageModelsQuery(int guserId);

  @Select("select * from transactions where guser_id = #{currentId} and tran_id = #{tranId}")
  Transaction selectRecord(int currentId, Integer tranId);

  @Delete("delete from transactions where guser_id = #{currentId} and tran_id = #{tranId}")
  void deleteTransaction(int currentId, Integer tranId);

//  @Select("select * from transactions where guser_id = #{guserId} and result_path LIKE '%#{fileName}%'")
//  Page<Transaction> recordsPageModelsQueryLimit(int guserId, String fileName);

  @Select("SELECT * FROM transactions WHERE guser_id = #{guserId} AND result_path LIKE CONCAT('%', #{fileName}, '%')")
  Page<Transaction> recordsPageModelsQueryLimit(@Param("guserId") int guserId, @Param("fileName") String fileName);

}
